home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dialog / checklist.c < prev    next >
C/C++ Source or Header  |  1995-12-28  |  1KB  |  72 lines

  1. /*
  2.  *  checklist.c -- implements the checklist box
  3.  *
  4.  */
  5.  
  6.  
  7. #include "dialog.h"
  8.  
  9. /*
  10.     Display a dialog box with a list of options that can be turned on or off
  11. */
  12. int dialog_checklist(
  13.     const char *title,
  14.     const char *prompt,
  15.     const char *helpfile,
  16.     int ,        //list_height,
  17.     int item_no,
  18.     char **items,
  19.     char *status)        /* Array of flags indicating if items[x] is */
  20.                         /* selected */
  21. {
  22.     int i;
  23.     int maxlen = 1;
  24.     for (i=0; i<item_no; i++){
  25.         int len = strlen(items[i*2]);
  26.         if (len > maxlen) maxlen = len;
  27.     }
  28.     DIALOG d;
  29.     for (i=0; i<item_no; i++){
  30.         char buf[100];
  31.         sprintf (buf,"%-*s %s",maxlen,items[i*2],items[i*2+1]);
  32.         d.newf_chk ("",status[i],buf);
  33.     }
  34.     return d.edit (title,prompt,helpfile,0);
  35. }
  36.     
  37. #ifdef TEST
  38. #include <string.h>
  39.  
  40. int main (int argc, char *argv[])
  41. {
  42.     static char *tb[]={
  43.         "a",    "message",
  44.         "allo",    "alal",
  45.         "b",    "bbbbbb",
  46.         "bozo",    "bzbzbzbz",
  47.         "c",    "coco",
  48.         "coco",    "cocococococ",
  49.         "d",    "dddd",
  50.         "dozo",    "dozozododo",
  51.     };
  52.     char status[8];
  53.     memset (status,0,8);
  54.     init_dialog();
  55.     int ret  = dialog_checklist(
  56.         "This is a test"
  57.         ,"Are you\nsure you want to exit\n"
  58.         ,"/tmp/dialog.bak"
  59.         ,5
  60.         ,8,tb,status);
  61.  
  62.  
  63.     endwin();
  64.     printf ("ret = %d\n",ret);
  65.     for (int i=0; i<8; i++){
  66.         printf ("%s %s %s\n",tb[i*2],tb[i*2+1],status[i] ? "On" : " ");
  67.     }
  68.     return 0;
  69. }
  70.  
  71. #endif
  72.